// MultiListCtrl.cpp: Implementierungsdatei
//

#include "stdafx.h"
#include "Charplan.h"
#include "CMultiListCtrl.h"


// CMultiListCtrl

IMPLEMENT_DYNAMIC(CMultiListCtrl, CListCtrl)

CMultiListCtrl::CMultiListCtrl()
{

}

CMultiListCtrl::~CMultiListCtrl()
{
}


BEGIN_MESSAGE_MAP(CMultiListCtrl, CListCtrl)
	ON_WM_SIZE()
END_MESSAGE_MAP()



// CMultiListCtrl-Meldungshandler


int		CMultiListCtrl::AddLine(const string& categorie)
{
	string text = categorie;

	int pos = ms_data_title.size();

	if (pos>0)
	{
		int p = pos-1;
		while (p>0 && ms_data_title[p].size()==0) p--;
		if (ms_data_title[p] == text)
		{
			text.erase();
		}
	}

	ms_data_title.push_back(text);
	struct_line_data temp;
	ms_data.push_back(temp);

	return pos;
}


int		CMultiListCtrl::AddText(int line, const string& txt1,const string& txt2)
{
	ms_data[line].text1.push_back(txt1);
	ms_data[line].text2.push_back(txt2);

	while (ms_data.size() > GetHeaderCtrl()->GetItemCount())
		InsertColumn(0,"");

	return (int)(ms_data.size()-1);
}


void	CMultiListCtrl::DeleteContents()
{
	ms_data.clear();
	ms_data_title.clear();
}

void CMultiListCtrl::OnSize(UINT nType, int cx, int cy)
{
	CListCtrl::OnSize(nType, cx, cy);

	int nr = GetHeaderCtrl()->GetItemCount();

	for (int t=0;t<nr;t++)
		SetColumnWidth(t,cx/nr);
}



/*

vector <string>::const_iterator iter_title	 = ms_data_title.begin();
vector <struct_line_data>::const_iterator iter_data = ms_data.begin();



int y = 0;

// Iterate through list and output each element.
for (;iter_data != ms_data.end() && y<rectText.bottom; iter_title++, iter_data++)
{
	if (!iter_title->empty())
	{
		dc.FillSolidRect(0,y,rectWnd.Width(),16,GetSysColor(COLOR_3DLIGHT));
		dc.TextOut(0,y+1,iter_title->c_str(),iter_title->size());
		dc.SetBkColor(GetSysColor(COLOR_WINDOW));
		y += fonthigh;
	}
	else
	{
		ASSERT(y>0);
		dc.Draw3dRect(	4,y,   
			rectText.Width()-8, 2,  
			::GetSysColor(COLOR_3DSHADOW),
			::GetSysColor(COLOR_3DHIGHLIGHT) );
		y += 4;
	}

	vector <string>::const_iterator iter_t1	 = iter_data->text1.begin();
	vector <string>::const_iterator iter_t2	 = iter_data->text2.begin();

	int x=0;
	for (;iter_t1 != iter_data->text1.end(); iter_t1++, iter_t2++)
	{
		dc.TextOut(x,y,iter_t1->c_str(),iter_t1->size());
		dc.TextOut(x,y+fonthigh,iter_t2->c_str(),iter_t2->size());
		x+=100;
	}
	y += fonthigh*2;

}
*/
